import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig({
	base: "./",
	server: {
		host: "127.0.0.1",
		https: false,
		port: 8089,
		open: true,
		proxy: {
			"/api": {
				target: "http://192.168.19.219:8082/gis",
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ""),
			},
			"/geniusspatialApi": {
				target: "http://192.168.19.106:8223",
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/geniusspatialApi/, ""),
			},
			"/tianditu": {
				target: "http://t4.tianditu.com",
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/tianditu/, ""),
			},
		},
	},
	plugins: [
		vue(),
		AutoImport({
			imports: ["vue", "vue-router", "pinia"],
			eslintrc: {
				enabled: true,
				filepath: "./.eslintrc-auto-import.json",
				globalsPropValue: true,
			},
			resolvers: [ElementPlusResolver()],
			dts: false,
		}),
	],
	resolve: {
		alias: {
			"@": fileURLToPath(new URL("./src", import.meta.url)),
			"@comp": fileURLToPath(new URL("./src/components", import.meta.url)),
		},
		extensions: [".js", "vue"],
	},
});
